using System; 
using Com.Mathphoenix.MapApps;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Com.Mathphoenix.MapApps.NerdDinner.Models;

namespace  Com.Mathphoenix.MapApps.NerdDinner.Controllers
{
    public class JsonDinner
    {
        public int DinnerID { get; set; }
        public string Title { get; set; }
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public string Description { get; set; }
        public int RSVPCount {get;set;}
    }
    public class SearchController : Controller
    {

        DinnerRepository dinnerRepository = new DinnerRepository();
        ////
        //// GET: /Search/

        //public ActionResult Index()
        //{
        //    return View();
        //}


        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SearchByLocation(float longitude, float latitude)
        {
            var dinners = dinnerRepository.FindByLocation(latitude, longitude);

            var jsonDinners = from dinner in dinners
                              select new JsonDinner
                              {
                                  DinnerID=dinner.DinnerID,
                                  Latitude=dinner.Latitude,
                                  Longitude=dinner.Longitude,
                                  Title=dinner.Title,
                                  Description=dinner.Description,
                                  RSVPCount=dinner.RSVP.Count
                              };
            return Json(jsonDinners.ToList());
        }
    }
}
